package com.service.edu.controller;


import com.service.edu.pojo.Chapter;
import com.service.edu.pojo.Video;
import com.service.edu.service.VideoService;
import com.service.utils.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-09-28
 */
@RestController
@RequestMapping("video")
@Api(description="课程小节管理")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 删除的课程小节信息
     * @param id
     * @return
     */
    @ApiOperation("删除课程小节信息")
    @DeleteMapping("{id}")
    public ResultVo delete(@ApiParam(name = "ids",value = "要删除的课程小节ID",required = true) @PathVariable String id){
        boolean b = videoService.removeById(id);
        if (b){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    /**
     * 修改课程小节信息
     * @param video
     * @return
     */
    @ApiOperation("修改课程小节信息")
    @PutMapping
    public ResultVo update(@RequestBody Video video){
        video.setGmtModified(new Date());
        boolean b = videoService.updateById(video);
        if (b){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    /**
     * 添加课程小节信息
     * @param video
     * @return
     */
    @ApiOperation("添加课程小节信息")
    @PostMapping
    public ResultVo save(@RequestBody  Video video){
        video.setGmtModified(new Date());
        video.setGmtCreate(new Date());
        boolean b = videoService.save(video);
        if (b){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

}

